package com.lw.controller;

import com.lw.common.utils.ResultVo;
import com.lw.entity.table.TbOperationLogTableDef;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import com.lw.entity.TbOperationLog;
import com.lw.service.TbOperationLogService;

import java.util.List;

import static com.lw.entity.table.TbOperationLogTableDef.TB_OPERATION_LOG;

/**
 * 操作日志 控制层。
 *
 * @author lw
 * @since 2025年04月30日 16:10:43
 */
@RestController
@Tag(name = "操作日志接口", description = "操作日志接口")
@RequestMapping("/tbOperationLog")
public class TbOperationLogController {

    @Resource
    private TbOperationLogService tbOperationLogService;

    /**
     * 添加操作日志。
     *
     * @param tbOperationLog 操作日志
     * @return {@code true} 添加成功，{@code false} 添加失败
     */
    @PostMapping("save")
    @Operation(summary = "保存操作日志")
    public ResultVo<Boolean> save(@RequestBody @Parameter(description = "操作日志") TbOperationLog tbOperationLog) {
        return ResultVo.success(tbOperationLogService.save(tbOperationLog));
    }

    /**
     * 根据主键删除操作日志。
     *
     * @param id 主键
     * @return {@code true} 删除成功，{@code false} 删除失败
     */
    @DeleteMapping("remove/{id}")
    @Operation(summary = "根据主键删除操作日志")
    public ResultVo<Boolean> remove(@PathVariable @Parameter(description = "操作日志主键") Long id) {
        return ResultVo.success(tbOperationLogService.removeById(id));
    }

    /**
     * 根据主键更新操作日志。
     *
     * @param tbOperationLog 操作日志
     * @return {@code true} 更新成功，{@code false} 更新失败
     */
    @PutMapping("update")
    @Operation(summary = "根据主键更新操作日志")
    public ResultVo<Boolean> update(@RequestBody @Parameter(description = "操作日志") TbOperationLog tbOperationLog) {
        return ResultVo.success(tbOperationLogService.updateById(tbOperationLog));
    }

    /**
     * 查询所有操作日志。
     *
     * @return 所有数据
     */
    @GetMapping("list")
    @Operation(summary = "查询所有操作日志")
    public ResultVo<List<TbOperationLog>> list() {
        return ResultVo.success(tbOperationLogService.list());
    }

    /**
     * 根据操作日志主键获取详细信息。
     *
     * @param id 操作日志主键
     * @return 操作日志详情
     */
    @GetMapping("getInfo/{id}")
    @Operation(summary = "根据主键获取操作日志")
    public ResultVo<TbOperationLog> getInfo(@PathVariable @Parameter(description = "操作日志主键") Long id) {
        return ResultVo.success(tbOperationLogService.getById(id));
    }

    /**
     * 分页查询操作日志。
     *
     * @return 分页对象
     */
    @GetMapping("page")
    @Operation(summary = "分页查询操作日志")
    public ResultVo<Page<TbOperationLog>> page(TbOperationLog operationLog,
                                               @RequestParam(defaultValue = "1") int pageNumber,
                                               @RequestParam(defaultValue = "10") int pageSize) {
        Page page = new Page(pageNumber, pageSize);
        return ResultVo.success(tbOperationLogService.pageWithCreatorName(page, operationLog));
    }
}